create or replace function insertPosterminalProducer(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 			alias for $1;
		posterminalProducerData		alias for $2;
		
		-- variable for node data
		vIdPosterminalProducer 		bigint := null; -- posterminal producer id in database
		vNameProducer				text := null; 	-- posterminal producer name
		
		-- node path
		vIdNode						varchar(100) := '/posterminalproducer/@id';
		vNameNode					varchar(100) := '/posterminalproducer/producername';
		
		
	begin
		-- get data from xml
		vIdPosterminalProducer := cast(extract_value(vIdNode, posterminalProducerData) as int);
		vNameProducer := extract_value(vNameNode, posterminalProducerData);
		
		-- insert data into table
		insert into PosterminalProducer(
				namePosterminalProducer)
			values(
				vNameProducer)
			returning idPosterminalProducer into vIdPosterminalProducer;
			posterminalProducerData := posterminalProducer2Xml(vIdPosterminalProducer, vNameProducer);
			
		executeStatusData := statusCall(successcode(), insertText()); -- status data
		return;

	end;
$$ language plpgsql VOLATILE;